package com.ant.storage.controller;


import com.ant.storage.common.ResultPage;
import com.ant.storage.common.ResultVo;
import com.ant.storage.dto.SalesDto;
import com.ant.storage.pojo.Sales;
import com.ant.storage.service.ISalesService;
import com.baomidou.mybatisplus.core.conditions.update.UpdateWrapper;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

/**
 * <p>
 *  前端控制器
 * </p>
 *
 * @author melon
 * @since 2022-11-03
 */
@RestController
@RequestMapping("/sales")
@Api(tags = "退料接口")
public class SalesController {

    @Autowired
    private ISalesService salesService;

    @ApiOperation(value = "获取退货单数据列表")
    @GetMapping("/getSalesList")
    public ResultPage getSalesList(SalesDto dto) {
        return ResultPage.success("获取成功",salesService.querylist(dto));
    }

    @ApiOperation(value = "保存退货单")
    @PostMapping("/saveSales")
    public ResultVo saveSales(@RequestBody  Sales sales) {
        return  salesService.saveSales(sales);
    }

    @ApiOperation(value = "修改退货单")
    @GetMapping("/SalesComplete/{id}")
    public ResultVo SalesComplete(@PathVariable(value = "id",required = false) Integer id) {
        if(id!=null){
            salesService.update(new UpdateWrapper<Sales>().set("status","1").eq("id",id));
            return ResultVo.success("获取成功");
        }else{
            return ResultVo.fail("请输入ID号");
        }
    }

    @ApiOperation(value = "通过id获取领料单详情")
    @GetMapping("/getSalesById/{id}")
    public ResultVo getSalesById(@PathVariable(value = "id",required = false) Integer id) {
        if(id!=null){
            return ResultVo.success("获取成功",salesService.getSalesByID(id));
        }else{
            return ResultVo.fail("请输入ID号");
        }
    }

    @ApiOperation(value = "删除")
    @PutMapping("/del/{id}")
    public ResultVo delPickingById(@PathVariable("id") Integer id) {
        if(id==null){
            return ResultVo.fail("id不能为空");
        }
       return salesService.updates(id);
    }

}
